package zee.com.customviewexample.recyclerviewUtil

import android.app.Activity
import android.content.pm.PackageInfo
import android.text.TextUtils
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.zee.adapter.BaseMultiZAdapter
import com.zee.adapter.MultiItemType
import com.zee.bean.MultiItemAdapter
import com.zee.log.ZLog
import com.zee.view.ZxRecyclerView
import zee.com.customviewexample.R

class MoreData(recyclerViwe: ZxRecyclerView, activity: Activity, list: ArrayList<PackageInfo>) {
    var adapter:BaseMultiZAdapter;
    init {
        val lists=ArrayList<BeanPerson>();
        lists.add(BeanPerson())
         adapter = object : BaseMultiZAdapter(lists) {
            override fun getMultiItemAdapter(viewType: Int): MultiItemAdapter {

                ZLog.i("leixing:" + viewType)
                val type = viewType % 2;
                when (type) {
                    0 -> return object : MultiItemAdapter() {
                        override fun getLayoutResID(): Int {
                            return R.layout.activity_zx_recyclerview_item;
                        }

                        override fun initViews(parentView: View?, location: Int) {
                            val pack = getBean<PackageInfo>()
                            curIndex
                            var name = pack.applicationInfo.loadLabel(activity.getPackageManager()).toString();
                            if (TextUtils.isEmpty(name)) {
                                name = "没有名字"
                            }
                            setText(R.id.app_name, name)

                            val iconIV = findViewById<ImageView>(R.id.app_icon)
                            val iconstr = pack.applicationInfo.loadIcon(activity.getPackageManager());
//                        Glide.with(this@ZxRecyclerViewActivity).load(iconstr).into(iconIV)
                            iconIV.setImageDrawable(iconstr)
                            setOnItemClickListener(iconIV)
                            val packIV = findViewById<TextView>(R.id.app_packName)
                            packIV.setText(pack.packageName)
                        }
                    }
                    else -> {
                        return object : MultiItemAdapter() {
                            override fun getLayoutResID(): Int {
                                return R.layout.activity_zx_recyclerview_item_b;
                            }

                            override fun initViews(parentView: View?, location: Int) {
                                val pack = getBean<PackageInfo>()
                                val nameTV = findViewById<TextView>(R.id.app_name)
                                var name = pack.applicationInfo.loadLabel(activity.getPackageManager()).toString();
                                if (TextUtils.isEmpty(name)) {
                                    name = "没有名字"
                                }
                                nameTV.setText(name)
                                val iconIV = findViewById<ImageView>(R.id.app_icon)
                                val iconstr = pack.applicationInfo.loadIcon(activity.getPackageManager());
//                        Glide.with(this@ZxRecyclerViewActivity).load(iconstr).into(iconIV)
                                iconIV.setImageDrawable(iconstr)
                                val packIV = findViewById<TextView>(R.id.app_packName)
                                packIV.setText(pack.packageName)
                            }
                        }
                    }
                }
            }
        }
        recyclerViwe.adapter = adapter;
    }

class  BeanPerson :MultiItemType {
    override fun getItemViewType(): Int {
            return 0
    }
}
}
